package com.demo.okio;

import okio.BufferedSink;
import okio.Okio;
import okio.Sink;

import java.io.File;
import java.io.IOException;
import java.util.Map;

public class OKioDemo {

    public static void writeEnv(File file) throws IOException {
        try (Sink fileSink = Okio.sink(file);
             BufferedSink bufferedSink = Okio.buffer(fileSink)) {

            for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
                bufferedSink.writeUtf8(entry.getKey());
                bufferedSink.writeUtf8("=");
                bufferedSink.writeUtf8(entry.getValue());
                bufferedSink.writeUtf8("\n");
            }

        }
    }

    public static void main(String[] args) {
        try {
            writeEnv(new File("./env.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
